<template>
  <div class="song-list">
    <div class="banner">
      <div
        class="mask"
        :style="{ background: 'url(' + playlistInfo.coverImgUrl + ')' }"
      ></div>
      <div class="pic">
        <div class="back" @click="back">&lt;</div>
        <div>
          <div class="img">
            <img :src="playlistInfo.coverImgUrl" width="94px" height="94px" />
          </div>
          <div class="te">
            <p class="text1">
              {{this.playlistInfo.name}}
            </p>
            <p class="text">
              {{ this.playlistInfo.description }}
            </p>
          </div>
        </div>
      </div>
    </div>
    <!-- 歌单列表 -->
    <div>
      <div
        v-for="(item, index) in hotSongList"
        :key="index"
        class="hotsonglist"
        @click="play(item.id)"
      >
        <span :class="['rank', { isred: index < 3 }]">{{
          Number(index + 1) > 9 ? Number(index + 1) : "0" + Number(index + 1)
        }}</span>

        <p>{{ item.name }}</p>
        <p class="artists">
          <i class="sq"></i>
          <span v-for="(artist, idx) in item.ar" :key="'artist' + idx">
            {{ artist.name }}
            
            <span v-if="item.ar.length > 1 && idx != item.ar.length - 1"
              >/</span
            >
          </span>
        </p>
        
        <span class="play"></span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 用来保存歌曲详情
      playlistInfo: {},
      hotSongList: [],
    };
  },
  created() {
    this.getPlaylistDetail();
  },
  methods: {
    getPlaylistDetail() {
      let id = this.$route.params.id;
      this.$http("/playlist/detail", { params: { id } })
        .then((res) => {
          this.playlistInfo = res.data.playlist;
          
          this.hotSongList = res.data.playlist.tracks;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    back() {
      this.$router.back();
    },
    
    // 跳转到播放页面
    play(id) {
      this.$router.push("/play/" + id);
    },
  },
};
</script>

<style scoped>
.song-list .banner {
  width: 100%;
  height: 180px;
  position: relative;
  overflow: hidden;
}
.song-list .mask {
  width: 100%;
  height: 180px;
  z-index: -1;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  background-repeat: no-repeat;
  background-size: cover;
  /* background-position: 50%; */
  filter: blur(20px);
  transform: scale(1.5);
}
.banner .pic {
  top: 25%;
  bottom: 0;
  z-index: 2;
  padding-left: 20px;
  box-sizing: border-box;
  position: relative;
}
.img {
  position: absolute;
  margin-top: 16px;
}
.te{
  position: absolute;
  margin-left: 100px;
  width: 215px;
  height: 200px;
  
}
.text1{
  color: #fff;
  font-size: 20px;
}
.text {
  color: #fff;
  font-size: 15px;
  display: -webkit-box;
  /* 文字总数为两行 */
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  /* 超出文字用省略号代替 */
  text-overflow: ellipsis;
  /* 超出部分隐藏 */
  overflow: hidden;
}
.back {
  color: #fff;
  font-size: 25px;
  position: absolute;
  left: 10px;
  top: -35px;
}
.hotsonglist {
  height: 76px;
  border-bottom: 1px solid #f4f4f4;
  font-size: 18px;
  padding-left: 40px;
  position: relative;
}
.artists {
  color: #666;
  font-size: 14px;
}
.sq {
  display: inline-block;
  width: 14px;
  height: 10px;
  background-image: url("../../static/img/index_icon_2x.png");
  background-position: 0 0;
  background-size: 190px 113px;
}
.rank {
  position: absolute;
  top: 0;
  left: 8px;
  font-size: 18px;
  line-height: 63px;
}
.isred {
  color: #f00;
}
.play {
  width: 45px;
  height: 45px;
  background-image: url(/static/img/index_icon_2x.5207a28.png);
  background-repeat: no-repeat;
  background-position: -47px 1px;
  position: absolute;
  right: 30px;
  top: 6px;
}
</style>